/*
 * Copyright 2008 Benjamin C. Meyer <ben@meyerhome.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */
/*
 * Copyright 2008 Benjamin C. Meyer <ben@meyerhome.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

#include "browserapplication.h"
#include "userprofile.h"

#ifdef Q_OS_WIN
#include "explorerstyle.h"
#endif

#include "utils/logger.h"
#include "nat/natnetwork.h"
#include "config/config.h"

#include <QFile>
#include "service/servicexml/servicexml.h"

static const std::string LOG_FILE_NAME = "ublog.log";
int main(int argc, char **argv)
{
    Logger::getInstance()->setLogFileName(LOG_FILE_NAME);
    LOG_DEBUG("start application");



    Q_INIT_RESOURCE(htmls);
    Q_INIT_RESOURCE(data);
    BrowserApplication application(argc, argv);
    if (!application.isRunning())
        return 0;
#ifdef Q_OS_WIN
    application.setStyle(new ExplorerStyle);
#endif

    UserProfile::getInstance();
    NatNetwork::getInstance()->init();


#if 0 //Test service xml
    LOG_DEBUG("Load service config file");
    QFile xml_file(QString::fromStdString(Config::getInstance()->getServiceConfigFile()));
    ServiceXml *xml = new ServiceXml(xml_file);

    std::string html = xml->postReceivedProcess();

    LOG_DEBUG("Html : %s", html.c_str());

#endif
    //UserProfile::getInstance()->start();
    LOG_DEBUG("open main window");
    application.newMainWindow();

    //test login window
    LOG_DEBUG("open login window");
    application.openLoginWindow();
    LOG_DEBUG("open login window end");
    // end

#if 1
    LOG_DEBUG("Load service config file");
    QFile xml_file(QString::fromStdString(Config::getInstance()->getServiceConfigFile()));
    ServiceXml *xml = new ServiceXml(xml_file);

    LOG_DEBUG("Ready to send service infomation xml: \n %s", xml->preSendProcess().c_str());

    std::string html = xml->postReceivedProcess();

    LOG_DEBUG("Html : %s", html.c_str());
#endif


    return application.exec();
}

